package alg20250217;

public class Text {
    public int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int left = 0, right = 0;
        int len = 0;
        while(right < n){
            //进窗口
            if(nums[right] == 0) k--;
            //判断
            while(k >= 0) {
                //出窗口
                if(nums[left++] == 0) k++;
            }
            //更新结果
            len = Math.max(len, right - left + 1);
            right++;
        }
        return len;
    }
}
